package ideamaps.action;

import ideamaps.Config;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.taillive.core.web.StrutsAction;


public class FileUploadAction extends StrutsAction {
	
	private File file;
	private String fileContentType;
	private String fileFileName;
	
	public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	
	public String upload() throws Exception {
		byte[] buffer = new byte[1024];
		InputStream in = new FileInputStream(file);
		OutputStream out = new FileOutputStream(new File(Config.getInstance().getUploadPath()+"/"+fileFileName));
		
		int length = in.read(buffer);
		while(length>0) {
			out.write(buffer);
			length = in.read(buffer);
		}
		
		in.close();
		out.flush();
		out.close();
		
		return SUCCESS;
		
	}

}
